package com.zero.business.bicycle.service.impl;

import com.github.pagehelper.PageHelper;
import com.zero.domain.Bicycle;
import com.zero.business.bicycle.mapper.BicycleMapper;
import com.zero.business.bicycle.service.BicycleService;
import com.zero.common.domain.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BicycleServiceImpl implements BicycleService{

    @Resource
    private BicycleMapper bicycleMapper;

    @Override
    public int deleteByPrimaryKey(Integer bicycleId) {
        return bicycleMapper.deleteByPrimaryKey(bicycleId);
    }

    @Override
    public int insert(Bicycle record) {
        return bicycleMapper.insert(record);
    }

    @Override
    public int insertSelective(Bicycle record) {
        return bicycleMapper.insertSelective(record);
    }

    @Override
    public Bicycle selectByPrimaryKey(Integer bicycleId) {
        return bicycleMapper.selectByPrimaryKey(bicycleId);
    }

    @Override
    public int updateByPrimaryKeySelective(Bicycle record) {
        return bicycleMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Bicycle record) {
        return bicycleMapper.updateByPrimaryKey(record);
    }

    /*
    *   分页展示所有未被使用的单车    status=0
    * */
    @Override
    public Page<Bicycle> getBicycle() {
        Page<Bicycle> page = new Page<>();

        // 开始分页查询     默认： pageNum=1   pageSize=10
        com.github.pagehelper.Page<Object> pageHelper = PageHelper.startPage(page.getPageNum(), page.getPageSize());
        // 执行分页查询
        List<Bicycle> bicycleList = bicycleMapper.getBicycle();

        // 总条数
        page.setTotalCount(pageHelper.getTotal());
        // 总页数
        page.setTotalPage(pageHelper.getPages());
        // 数据
        page.setData(bicycleList);   // pageHelper.getResult()

        return page;
    }

}
